# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libunistring
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.10
pkgrel=2
pkgdesc="Library for manipulating Unicode strings and C strings. (mingw-w64)"
arch=('any')
url="https://www.gnu.org/software/libunistring"
license=('LGPL' 'GPL3')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-libiconv")
options=('staticlibs' 'strip')
source=("https://ftp.gnu.org/gnu/libunistring/${_realname}-${pkgver}.tar.gz"
        fix-pointer-casts.patch)
sha256sums=('a82e5b333339a88ea4608e4635479a1cfb2e01aafb925e1290b65710d43f610b'
            '77ae425f982b61ae69c53f689f90a0a57706be73298acb1df61cca74855edf69')

prepare() {
  cd ${srcdir}/libunistring-${pkgver}
  patch -Nbp1 -i ${srcdir}/fix-pointer-casts.patch
}

build() {
  #export lt_cv_deplibs_check_method='pass_all'
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../libunistring-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-threads=win32

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LIB"
}
